//
//  SHMenuCollectionViewCell.m
//  吃货·上海
//
//  Created by lanou on 15/11/24.
//  Copyright © 2015年 濮亚军. All rights reserved.
//

#import "SHMenuCollectionViewCell.h"
#import "UIImageView+WebCache.h"

@interface SHMenuCollectionViewCell ()
//图片 和 标题
@property(nonatomic,strong)UIImageView *icon;
@property(nonatomic,strong)UILabel *label;

@end


@implementation SHMenuCollectionViewCell

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.icon = [[UIImageView alloc]initWithFrame:self.bounds];
        [self.contentView addSubview:_icon];
        
        UIView *view = [[UIView alloc]initWithFrame:self.bounds];
        view.backgroundColor = [UIColor blackColor];
        view.alpha = 0.3;
        [self.contentView addSubview:view];
        
        self.label = [[UILabel alloc]initWithFrame:self.bounds];
        self.label.font =[UIFont systemFontOfSize:18];
        self.label.numberOfLines = 0;
        self.label.textAlignment = NSTextAlignmentCenter;
        self.label.textColor =[UIColor whiteColor];
        
        [self.contentView addSubview:_label];
        
        //添加一个手势
        UILongPressGestureRecognizer *longPress =[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longAction:)];
        longPress.minimumPressDuration = 0.5;
        [view addGestureRecognizer:longPress];
        
    }
    
    return self;
}

//设置一个手势动画
- (void)longAction:(UILongPressGestureRecognizer *)longPress
{
    UIView *view = longPress.view;
    if (longPress.state == UIGestureRecognizerStateBegan) {
        [UIView animateWithDuration:0.5 animations:^{
            view.alpha = 0;
            self.label.alpha = 0;
        }];
    }
    else if(longPress.state  == UIGestureRecognizerStateEnded)
    {
        [UIView animateWithDuration:0.5 animations:^{
            view.alpha = 0.3;
            self.label.alpha = 1;
        }];
    }
}


- (void)setModel:(SHMenuModel *)model
{
    _model = model;
    
    [self.icon sd_setImageWithURL:[NSURL URLWithString:model.imageUrl]];
     self.label.text = model.title;
}


@end
